package leecode

func oddEvenList(head *ListNode) *ListNode {
	if head == nil {
		return nil
	}
	if head.Next == nil {
		return head
	}
	hashMap := make(map[int]int)
	index := 0
	for head != nil {
		hashMap[index] = head.Val
		index++
		head = head.Next
	}
	leftNode, rightNode := &ListNode{Val: hashMap[0]}, &ListNode{Val: hashMap[1]}
	left, right := leftNode, rightNode
	for i := 2; i < index; i++ {
		if i%2 == 0 {
			//偶数
			left.Next = &ListNode{Val: hashMap[i]}
			left = left.Next
		} else {
			//奇数
			right.Next = &ListNode{Val: hashMap[i]}
			right = right.Next
		}
	}
	left.Next = rightNode
	return leftNode
}
